package thread.java20230105;

public class Singleton2 {
    //1. 构造函数私有化
    private Singleton2() {
    }

    //2. 创建实例, 不进行初始化
    private static volatile Singleton2 instance = null;

    //3. 提供一个方法, 获取该实例, 并进行初始化
    public static Singleton2 getInstance() {
        if (instance == null){
            synchronized (Singleton2.class){
                if (instance == null) {
                    instance = new Singleton2();
                }
            }
        }

        return instance;
    }
}
